home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / SOUND.SWG / 0058_Programming the PC-Speaker.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  3KB  |  96 lines

  1. {
  2. >I want to build on Infared Controller (thru RC5 coding) to controll my
  3. >tv, stereo, ect thru my PC. I know how to programm the computer to do so,
  4. >but I need to access my PC-Speaker directly !!!
  5. >Does anyone know the Port Adress or Mem Adress for accessing the PC-Speaker
  6.  
  7. Here's some BASM code of mine; check the comments:
  8. From: ljduchez@en.com (Lou DuChez)
  9. }
  10.  
  11. asm
  12.   mov al, 182       { prepare timer to start generating sound }
  13.   out 43h, al
  14.   mov ax, toneout   { TONEOUT = word: 1193180 / frequency }
  15.   out 42h, al       { send low byte to port 42h }
  16.   mov al, ah
  17.   out 42h, al       { send high byte to port 42h }
  18.   in al, 61h        { get current value of port 61h }
  19.   or al, 3          { set lowest two bits of 61h "on" -- activate speaker }
  20.   out 61h, al       { rewrite to port 61h }
  21. end;
  22.  
  23. { This code turns off the speaker: }
  24.  
  25. asm
  26.   in al, 61h        { set lowest two bits of 61h "off" -- deactive speaker }
  27.   and al, 252       { this line turns the lowest two bits "off" }
  28.   out 61h, al
  29. end;
  30.  
  31. {
  32. > If I know this adress, all you have to do is buy a IR-Led ($1,00) and your
  33. > computer is the biggest enhanced remote controller.
  34. }
  35.  
  36. {
  37. From: -deneb- <NWIEFFER@norton.ctech.ac.za>
  38.  
  39. > I want to build on Infared Controller (thru RC5 coding) to controll my
  40. > tv, stereo, ect thru my PC. I know how to programm the computer to do so,
  41. > but I need to access my PC-Speaker directly !!!
  42. > Does anyone know the Port Adress or Mem Adress for accessing the PC-Speaker
  43.  
  44. Well .... it's not half as easy as it could be ...
  45.  
  46. There are a few way to fiddle with the speaker ...
  47.  
  48.  1.  Via the 8254 Programmable Interval Timer (PIT). (Port $40-$47)
  49.  2.  Via the 8255 Programmable Peripheral Interface. (Port $60-$67)
  50.  
  51.  ( on the original PC, XT and earlier 286's these were seperate IC's,
  52.    but now all of that stuff is combined into 1 along with the DMA
  53.    controler, etc.)
  54.  
  55. With option 1 you can tell the timer to drive the speaker at a
  56. certain frequency ... and that's about it,
  57. or with option 2 you can waggle the speaker bit up and down as you
  58. like ...
  59.  
  60. For your application, I think option 2 would be the 1 to choose.
  61. So here goes ...
  62. }
  63.  
  64. { This should push the output high }
  65. x:=Port[$61];
  66. x:=(x and $FC) or 2;
  67. Port[$61]:=x;
  68.  
  69. { And this should push it low }
  70. x:=Port[$61];
  71. x:=x and $FC
  72. Port[$61]:=x;
  73.  
  74. {
  75. And hear's what is actually does ...
  76.  
  77. Port $61 is the 8255 port B.
  78. If bit 0 of port B is 0, then the speaker does exactly what bit 1
  79. does ... that's what I'm doing above.
  80.  
  81. In this mode the port can go like this ...
  82.  
  83. Port B bit 1 : 1    0    1    0
  84. Speaker port : High Low  High Low
  85.  
  86.  
  87. If bit 0 of port B is 1, then the speaker is conected to the PIT,
  88. in which case Bit 1 acts as the switch ... it either connects it to
  89. the PIT, or it switches it off.
  90.  
  91. And in this mode the port goes somthing like this ...
  92.  
  93. Port B bit 1 : 1    0    1    0
  94. Speaker Port : Beep Off  Beep Off
  95. }
  96.